package com.luobd.bpm.controller;

import com.luobd.bpm.business.process.dto.ProcessXmlDto;
import com.luobd.bpm.business.process.input.DeployProcessInput;
import com.luobd.bpm.business.process.input.ProcessDefinitionInput;
import com.luobd.bpm.business.process.input.ProcessDefinitionPageQueryInput;
import com.luobd.bpm.business.process.service.IProcessDefService;
import com.luobd.bpm.common.ResponseData;
import com.luobd.bpm.common.ResponsePageData;
import com.luobd.bpm.dto.ProcessDefinitionDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/api/bpmn/def")
@Api(tags = "流程定义管理-自定义")
public class ProcessDefinitionController {

    @Resource
    private IProcessDefService processDefService;



    @PostMapping(value = "/saveOrUpdate")
    @ApiOperation(value = "保存或更新流程定义")
    public ResponseData<Long> saveOrUpdate(@RequestBody ProcessDefinitionInput input) {
        return processDefService.saveOrUpdate(input);
    }


    @PostMapping(value = "/page")
    @ApiOperation(value = "分页查询流程定义")
    public ResponsePageData<ProcessDefinitionDTO> page(@RequestBody ProcessDefinitionPageQueryInput input) {
        return processDefService.page(input);
    }


    @PostMapping(value = "/deployment")
    @ApiOperation(value = "部署流程")
    public ResponseData<String> deployment(@RequestBody DeployProcessInput input) {
        System.out.println(input.getBpmnXml());
        return processDefService.deployment(input);
    }


    @GetMapping(value = "/delete")
    @ApiOperation(value = "删除流程定义")
    public ResponseData<Boolean> deleteById(@RequestParam(value = "id") Long id) {
        return processDefService.delete(id);
    }


    @GetMapping(value = "/getProcessXml")
    @ApiOperation(value = "获取流程定义xml")
    public ResponseData<ProcessXmlDto> getProcessXml(@RequestParam(value = "id") Long id) {
        return processDefService.getProcessXml(id);
    }

    @GetMapping(value = "/getProcessXmlByDefinitionId")
    @ApiOperation(value = "获取流程定义xml")
    public ResponseData<ProcessXmlDto> getProcessXmlByDefinitionId(@RequestParam(value = "processDefinitionId") String processDefinitionId) {
        return processDefService.getProcessXml(processDefinitionId);
    }

}
